package org.chameleon.threadpool.factory;

import org.chameleon.datasource.factory.AbsDynamicCacheFactory;
import org.chameleon.lang.ConfigAbleManager;
import org.chameleon.threadpool.entity.ThreadPoolConfig;
import org.chameleon.threadpool.pool.DynamicThreadPool;

public class DynamicThreadPoolFactory extends AbsDynamicCacheFactory<ThreadPoolConfig, DynamicThreadPool> {

    private static final String CACHE_PREFIX = "DynamicThreadPoolFactory:";

    public DynamicThreadPoolFactory(ConfigAbleManager<ThreadPoolConfig> manager) {
        super(manager);
    }

    public DynamicThreadPoolFactory() {
    }

    @Override
    public DynamicThreadPool create(ThreadPoolConfig threadPoolConfig) {
        return new DynamicThreadPool(threadPoolConfig);
    }

    @Override
    public String getCacheKey(ThreadPoolConfig threadPoolConfig) {
        return CACHE_PREFIX + ":" + threadPoolConfig.getPoolName();
    }
}
